﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;

namespace Partner.Surround.Authorization
{
    public class SurroundAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            #region 顶级权限
            var pages = context.CreatePermission(PermissionNames.Pages, L("Pages"));
            #endregion

            #region 基础支撑平台
            context.CreatePermission(PermissionNames.Pages_Users, L("Users"));
            context.CreatePermission(PermissionNames.Pages_Roles, L("Roles"));
            context.CreatePermission(PermissionNames.Pages_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);
            #endregion

            #region 业务模块
            context.CreatePermission(PermissionNames.Pages_TaskManage, L("TaskManage"));
            #endregion

            #region 基础设施管理
            var coreManages = pages.CreateChildPermission(PermissionNames.Pages_Core, L("CoreManage"));

            #region 数据字典
            var datadictionaries = coreManages.CreateChildPermission(PermissionNames.Pages_Core_DataDictionary, L("DataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Core_DataDictionary_Create, L("CreateDataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Core_DataDictionary_Edit, L("EditDataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Core_DataDictionary_Delete, L("DeleteDataDictionary"));
            #endregion

            #region 数据字典项
            var datadictionaryItems = coreManages.CreateChildPermission(PermissionNames.Pages_Core_DataDictionaryItem, L("DataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Core_DataDictionaryItem_Create, L("CreateDataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Core_DataDictionaryItem_Edit, L("EditDataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Core_DataDictionaryItem_Delete, L("DeleteDataDictionaryItem"));
            #endregion

            #endregion
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, SurroundConsts.LocalizationSourceName);
        }
    }
}
